
using Qdb;
using Qdb.Config;
using Qdb.Ext;
using Qdb.Foundation;
using Qdb.Drs.Qdb;
using Qdb.Drs.Tests;

namespace Qdb.Drs.Tests
{
	public class QdbClientServerDrsFixture : QdbDrsFixture
	{
		private static readonly string Host = "localhost";

		private static readonly string Username = "qdb";

		private static readonly string Password = Username;

		private IObjectServer _server;

		private int _port;

		public QdbClientServerDrsFixture(string name, int port) : base(name)
		{
			_port = port;
		}

		public override void Close()
		{
			base.Close();
			_server.Close();
		}

		public override void Open()
		{
			Config().MessageLevel(-1);
			_server = QdbFactory.OpenServer(CloneConfiguration(), testFile.GetPath
				(), _port);
			_server.GrantAccess(Username, Password);
			_db = (IExtObjectContainer)QdbFactory.OpenClient(CloneConfiguration
				(), Host, _port, Username, Password);
			_provider = QdbProviderFactory.NewInstance(_db, _name);
		}

		private IConfiguration CloneConfiguration()
		{
			return (IConfiguration)((IDeepClone)Config()).DeepClone(Config());
		}
	}
}
